<%--
  Created by IntelliJ IDEA.
  User: Administrator
  Date: 2018/4/28
  Time: 13:27
  To change this template use File | Settings | File Templates.
--%>
<%@ page contentType="text/html;charset=UTF-8" language="java" %>
<%@taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core" %>

<!doctype html>
<html>

<%@include file="../../layout/css.jsp" %>

<body class="page-container-bg-solid">
<div class="page-wrapper">
    <div class="page-wrapper-row">
        <div class="page-wrapper-top">
            <div class="page-header">
                <%@include file="../../layout/nav-topmenu.jsp" %>
            </div>
        </div>
    </div>
    <div class="page-wrapper-row full-height">
        <div class="page-wrapper-middle">
            <div class="page-content">
                <div class="container-fluid">
                    <ul class="page-breadcrumb breadcrumb">
                        <li>
                            <span>&nbsp;&nbsp;</span>
                            <a href="${pageContext.request.contextPath}/">首页</a>
                            <i class="fa fa-chevron-right"></i>
                        </li>
                        <li>
                            <span>${title}列表</span>
                        </li>
                    </ul>
                    <div class="row">
                        <div class="col-md-12">
                            <div class="portlet light">
                                <div class="portlet-title">
                                    <div class="caption">
                                        <i class="icon-user font-green"></i>
                                        <span class="caption-subject bold font-green">${title}列表</span>
                                    </div>
                                    <div class="actions">
                                        <div class="btn green" onclick="addUser()">
                                            <i class="fa fa-plus"></i>&nbsp;&nbsp;新增
                                        </div>
                                    </div>
                                </div>
                                <div class="portlet-body">
                                    <div class="row">
                                        <%@include file="../../layout/search.jsp" %>
                                    </div>
                                    <div class="table-scrollable">
                                        <table class="table table-bordered table-hover">
                                            <thead>
                                            <tr>
                                                <th>ID</th>
                                                <th>用户名</th>
                                                <th>真实姓名</th>
                                                <th>所在部门</th>
                                                <th>手机号码</th>
                                                <th>邮箱地址</th>
                                                <th style="width: 100px;">激活</th>
                                                <th style="width: 200px;">操作</th>
                                            </tr>
                                            </thead>
                                            <tbody>
                                            <c:forEach items="${pageInfo.list}" var="record">
                                                <tr>
                                                    <td>${record.id}</td>
                                                    <td>${record.userName}</td>
                                                    <td>${record.realName}</td>
                                                    <td>${record.deptName}</td>
                                                    <td>${record.phone}</td>
                                                    <td>${record.email}</td>
                                                    <td>
                                                        <c:choose>
                                                            <c:when test="${record.active}"><span
                                                                    style="color: green; font-weight: bold;">是</span></c:when>
                                                            <c:when test="${!record.active}"><span
                                                                    style="color: darkred; font-weight: bold;">否</span></c:when>
                                                        </c:choose>
                                                    </td>
                                                    <td>
                                                        <div class="btn-group">
                                                            <a class="btn btn-sm green-meadow"
                                                               href="${pageContext.request.contextPath}/auth/user/update/${record.id}">编辑</a>
                                                            <a class="btn btn-sm red" href="javascript:;"
                                                               onclick="deleteUser('${record.id}')">删除</a>
                                                            <a class="btn btn-sm blue"
                                                               href="javascript:;"
                                                               onclick="resetPwd('${record.id}')">重置密码</a>
                                                        </div>
                                                    </td>
                                                </tr>
                                            </c:forEach>
                                            </tbody>
                                        </table>
                                    </div>
                                    <div class="row" style="margin:0px;">
                                        <%@include file="../../layout/pageinfo.jsp" %>
                                    </div>
                                </div>
                            </div>
                        </div>
                    </div>
                </div>
            </div>
        </div>
    </div>
    <%@include file="../../layout/footer.jsp" %>
</div>

<%@include file="../../layout/script.jsp" %>

<script>
    $(function () {
    });

    function addUser() {
        if (confirm("您确定要新增用户吗？")) {
            $.post("${pageContext.request.contextPath}/auth/user/create", function (data) {
                if (data['code'] === 200) {
                    window.location.href = "${pageContext.request.contextPath}/auth/user/update/" + data['data'];
                } else {
                    toastr.error(data['message']);
                }
            }, 'json');
        }
    }

    function deleteUser(id) {
        if (confirm("您确定要删除该用户吗？")) {
            $.post("${pageContext.request.contextPath}/auth/user/delete", {
                id: id
            }, function (data) {
                if (data['code'] === 200) {
                    alert(data['message']);
                    location.reload();
                } else {
                    toastr.error(data['message']);
                }
            }, 'json');
        }
    }

    function resetPwd(id) {
        if (confirm("您确定要重置密码吗？(重置密码为123456)")) {
            $.post("${pageContext.request.contextPath}/auth/user/resetPassword", {
                id: id
            }, function (data) {
                if (data['code'] === 200) {
                    toastr.success(data['message']);
                } else {
                    toastr.error(data['message']);
                }
            }, 'json');
        }
    }
</script>
</body>
</html>
